/*
 * @title: 通用请求api
 * @author: andy.ten@tom.com & xukaixing@hotmail.com
 * @Date: 2022-04-09 21:07:08
 * @LastEditors: andy.ten@tom.com
 * @LastEditTime: 2022-06-06 11:41:00
 * @version: 1.0.6
 * @copyright: copyright (c) 2022 andyten
 *  node: you can not copy and/or use and/or modify this program free,
 *  please reserve the segment above.Please mail me if you have any question.
 */
import fetch, { setHeaders } from '@/utils/ht.fetch';
import server from '@/api/ht.server';
import AppConfig from '@/appconfig';
// setHeaders
export const setHeader = () => {
  return setHeaders();
};

// dict请求api
export const loadDict = () => {
  if (process.env.NODE_ENV !== 'production') fetch.defaults.baseURL = AppConfig.gateWayUrl;
  return fetch.get(`${server.gateway_dict}/sysdict/findDict`);
};

// dict表选字典api
export const findDictFromTable = (dicType, q) => {
  if (process.env.NODE_ENV !== 'production') fetch.defaults.baseURL = AppConfig.gateWayUrl;
  return fetch.get(`${server.gateway_dict}/sysdict/findDictFromTable`, {
    params: {
      vparam: dicType,
      query: q === undefined ? '' : q
    }
  });
};

// filestore
export const upload = () => {
  return `${AppConfig.gateWayUrl}${server.gateway_filestore}/sysattachminio/upload`;
};

// filestore 下载附件
export const download = (data) => {
  if (process.env.NODE_ENV !== 'production') fetch.defaults.baseURL = AppConfig.gateWayUrl;
  return fetch.post(`${server.gateway_filestore}/sysattachminio/download`, data, {
    responseType: 'blob'
  });
};

// filestore 删除附件
export const removeAttach = (data) => {
  if (process.env.NODE_ENV !== 'production') fetch.defaults.baseURL = AppConfig.gateWayUrl;
  return fetch.post(`${server.gateway_filestore}/sysattachminio/remove`, data);
};

// 获取excel导入模版信息
export const findImportTemplateInfo = (fileName) => {
  if (process.env.NODE_ENV !== 'production') fetch.defaults.baseURL = AppConfig.gateWayUrl;
  return fetch.get(`${server.gateway_filestore}/sysattachminio/findImportTemplateInfo`, {
    params: {
      fileName
    }
  });
};

// filestore 导入excel
export const importXls = () => {
  if (process.env.NODE_ENV !== 'production') fetch.defaults.baseURL = AppConfig.gateWayUrl;
  return fetch.get(`${server.gateway_filestore}/sysattachminio/upload`);
};
